package spring.data.redis.demo;

import java.time.Clock;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class StudentHibernateCacheDaoTest {

	ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
	StudentRedisDao dao = context.getBean(StudentRedisDao.class);
	
	@Test
	public void save(){
		
		Student Student = new Student("1", "1", 10);
		dao.save(Student);
	}
	
	@Test
	public void get(){
		
		Student Student = dao.read("1");
		System.out.println(Student);
	}
	
	@Test
	public void delete(){
		
		dao.delete("1");
	}
	
	@Test
	public void saveBigData(){
		
		long start = Clock.systemUTC().millis();
		for(int i = 0; i < 1000_00; i++){
			
			String number = String.valueOf(i);
			Student Student = new Student(number, number, i);
			dao.save(Student);
		}
		long end = Clock.systemUTC().millis();
		System.out.println("共耗时：" + ((end - start) / 1000.0) + "秒");
	}
	
	@Test
	public void deleteBigData(){
		
		long start = Clock.systemUTC().millis();
		for(int i = 0; i < 1000_00; i++){
			
			dao.delete(String.valueOf(i));
		}
		long end = Clock.systemUTC().millis();
		System.out.println("共耗时：" + ((end - start) / 1000.0) + "秒");
	}
}
